/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 05.03.2012 by jkonopka
 */
package de.sql.toolkit.generator;

import java.io.File;

import de.sql.toolkit.model.Column;
import de.sql.toolkit.model.Table;
import de.sql.toolkit.util.StringUtil;

/**
 * @author jkonopka
 * 
 */
public class JvModelGetterGenerator extends AbstractJvModelGenerator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3961340304640142014L;

	/**
	 * @param dstPath
	 * @param table
	 */
	public JvModelGetterGenerator(File dstPath, Table table) {
		super(dstPath, table);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.IWriter#write()
	 */
	@Override
	public String generate() throws Exception {
		final StringBuilder content = new StringBuilder();
		for (final Column column : getTable().getColumns()) {
			final String type = getFieldType(column.getType(), column.getNullable());
			content.append("\tpublic ");
			content.append(type);
			content.append(" ");
			if (type.equals("boolean")) {
				content.append("is");
			} else {
				content.append("get");
			}
			content.append(StringUtil.upperCaseFirstLetters(column.getName()));
			content.append("() {\n");
			content.append("\t\treturn this.");
			content.append(prepareName(column.getName()));
			content.append(";\n\t}\n\n");
		}
		return content.toString();
	}

}
